home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
kernel
/
system.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-23
|
33KB
|
959 lines
/* This task handles the interface between file system and kernel as well as
* between memory manager and kernel. System services are obtained by sending
* sys_task() a message specifying what is needed. To make life easier for
* MM and FS, a library is provided with routines whose names are of the
* form sys_xxx, e.g. sys_xit sends the SYS_XIT message to sys_task. The
* message types and parameters are:
*
* SYS_FORK informs kernel that a process has forked
* SYS_NEWMAP allows MM to set up a process memory map
* SYS_EXEC sets program counter and stack pointer after EXEC
* SYS_XIT informs kernel that a process has exited
* SYS_GETSP caller wants to read out some process' stack pointer
* SYS_TIMES caller wants to get accounting times for a process
* SYS_ABORT MM or FS cannot go on; abort MINIX
#if (CHIP == M68000)
* SYS_FRESH start with a fresh process image during EXEC
#endif
* SYS_SIG send a signal to a process
* SYS_KILL cause a signal to be sent via MM
* SYS_COPY requests a block of data to be copied between processes
* SYS_GBOOT copies the boot parameters to a process
* SYS_UMAP compute the physical address for a given virtual address
* SYS_MEM returns the next free chunk of physical memory
* SYS_TRACE request a trace operation
*
* Message type m1 is used for all except SYS_SIG and SYS_COPY, both of
* which need special parameter types.
*
* m_type PROC1 PROC2 PID MEM_PTR
* ------------------------------------------------------
* | SYS_FORK | parent | child | pid | |
* |------------+---------+---------+---------+---------|
* | SYS_NEWMAP | proc nr | | | map ptr |
* |------------+---------+---------+---------+---------|
* | SYS_EXEC | proc nr | traced | new sp | |
* |------------+---------+---------+---------+---------|
* | SYS_XIT | parent | exitee | | |
* |------------+---------+---------+---------+---------|
* | SYS_GETSP | proc nr | | | |
* |------------+---------+---------+---------+---------|
* | SYS_TIMES | proc nr | | buf ptr | |
* |------------+---------+---------+---------+---------|
* | SYS_ABORT | | | | |
#if (CHIP == M68000)
* |------------+---------+---------+---------+---------|
* | SYS_FRESH | proc nr | data_cl | | |
#endif
* |------------+---------+---------+---------+---------|
* | SYS_GBOOT | proc nr | | | bootptr |
* ------------------------------------------------------
*
*
* m_type m2_i1 m2_i2 m2_l1 m2_l2
* ------------------------------------------------------
* | SYS_TRACE | proc_nr | request | addr | data |
* ------------------------------------------------------
*
*
* m_type m6_i1 m6_i2 m6_i3 m6_f1
* ------------------------------------------------------
* | SYS_SIG | proc_nr | sig | | handler |
* ------------------------------------------------------
* | SYS_KILL | proc_nr | sig | | |
* ------------------------------------------------------
*
*
* m_type m5_c1 m5_i1 m5_l1 m5_c2 m5_i2 m5_l2 m5_l3
* --------------------------------------------------------------------------
* | SYS_COPY |src seg|src proc|src vir|dst seg|dst proc|dst vir| byte ct |
* --------------------------------------------------------------------------
* | SYS_UMAP | seg |proc nr |vir adr| | | | byte ct |
* --------------------------------------------------------------------------
*
*
* mem_type DEVICE PROC_NR COUNT POSITION
* |------------+---------+---------+---------+---------|
* | SYS_MEM | extflag | |mem size |mem base |
* ------------------------------------------------------
*
* In addition to the main sys_task() entry point, there are 5 other minor
* entry points:
* cause_sig: take action to cause a signal to occur, sooner or later
* inform: tell MM about pending signals
* numap: umap D segment starting from process number instead of pointer
* umap: compute the physical address for a given virtual address
* alloc_segments: allocate segments for 8088 or higher processor
*/
#include "kernel.h"
#include <signal.h>
#include <minix/boot.h>
#include <minix/callnr.h>
#include <minix/com.h>
#include "proc.h"
#if (CHIP == INTEL)
#include "protect.h"
#endif
PRIVATE message m;
PRIVATE char sig_stuff[SIG_PUSH_BYTES]; /* used to send signals to processes */
FORWARD int do_abort();
FORWARD int do_copy();
FORWARD int do_exec();
FORWARD int do_fork();
FORWARD int do_gboot();
FORWARD int do_getsp();
FORWARD int do_kill();
FORWARD int do_mem();
FORWARD int do_newmap();
FORWARD int do_sig();
FORWARD int do_times();
FORWARD int do_trace();
FORWARD int do_umap();
FORWARD int do_xit();
#if (CHIP == M68000)
FORWARD void build_sig();
#endif
/*===========================================================================*
* sys_task *
*===========================================================================*/
PUBLIC void sys_task()
{
/* Main entry point of sys_task. Get the message and dispatch on type. */
register int r;
while (TRUE) {
receive(ANY, &m);
switch (m.m_type) { /* which system call */
case SYS_FORK: r = do_fork(&m); break;
case SYS_NEWMAP: r = do_newmap(&m); break;
case SYS_EXEC: r = do_exec(&m); break;
case SYS_XIT: r = do_xit(&m); break;
case SYS_GETSP: r = do_getsp(&m); break;
case SYS_TIMES: r = do_times(&m); break;
case SYS_ABORT: r = do_abort(&m); break;
#if (CHIP == M68000)
case SYS_FRESH: r = do_fresh(&m); break;
#endif
case SYS_SIG: r = do_sig(&m); break;
case SYS_KILL: r = do_kill(&m); break;
case SYS_COPY: r = do_copy(&m); break;
case SYS_GBOOT: r = do_gboot(&m); break;
case SYS_UMAP: r = do_umap(&m); break;
case SYS_MEM: r = do_mem(&m); break;
case SYS_TRACE: r = do_trace(&m); break;
default: r = E_BAD_FCN;
}
m.m_type = r; /* 'r' reports status of call */
send(m.m_source, &m); /* send reply to caller */
}
}
/*===========================================================================*
* do_fork *
*===========================================================================*/
PRIVATE int do_fork(m_ptr)
register message *m_ptr; /* pointer to request message */
{
/* Handle sys_fork(). m_ptr->PROC1 has forked. The child is m_ptr->PROC2. */
#if (CHIP == INTEL)
reg_t old_ldt_sel;
#endif
register struct proc *rpc;
struct proc *rpp;
if (!isoksusern(m_ptr->PROC1) || !isoksusern(m_ptr->PROC2))
return(E_BAD_PROC);
rpp = proc_addr(m_ptr->PROC1);
rpc = proc_addr(m_ptr->PROC2);
/* Copy parent 'proc' struct to child. */
#if (CHIP == INTEL)
old_ldt_sel = rpc->p_ldt_sel; /* stop this being obliterated by copy */
*rpc = *rpp;
rpc->p_ldt_sel = old_ldt_sel;
#else
phys_copy( rpp, (phys_bytes)proc_addr(m_ptr->PROC2),
(phys_bytes)sizeof(struct proc));
#endif
rpc->p_nr = m_ptr->PROC2; /* this was obliterated by copy */
#if (CHIP != M68000)
rpc->p_flags |= NO_MAP; /* inhibit the process from running */
#endif
rpc->p_flags &= ~(PENDING | SIG_PENDING | P_STOP);
/* only one in group should have PENDING */
/* child does not inherit trace status */
rpc->p_pending = 0;
rpc->p_pendcount = 0;
rpc->p_pid = m_ptr->PID; /* install child's pid */
rpc->p_reg.retreg = 0; /* child sees pid = 0 to know it is child */
rpc->user_time = 0; /* set all the accounting times to 0 */
rpc->sys_time = 0;
rpc->child_utime = 0;
rpc->child_stime = 0;
#if (CHIP == M68000)
rpc->p_nflips = 0;
mkshadow(rpp, (phys_clicks)m_ptr->m1_p1); /* run child first */
#endif
return(OK);
}
/*===========================================================================*
* do_newmap *
*===========================================================================*/
PRIVATE int do_newmap(m_ptr)
message *m_ptr; /* pointer to request message */
{
/* Handle sys_newmap(). Fetch the memory ma